/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package org.ipti.br.tag.dao;

import org.ipti.br.tag.entity.SynchController;
import org.ipti.br.tag.entity.SynchController_;
import javax.ejb.Stateless;
import javax.persistence.EntityManager;
import javax.persistence.NoResultException;
import javax.persistence.PersistenceContext;
import javax.persistence.criteria.CriteriaBuilder;
import javax.persistence.criteria.CriteriaQuery;
import javax.persistence.criteria.Root;

/**
 *
 * @author israel
 */
@Stateless
public class SynchControllerFacade extends AbstractFacade<SynchController> {

    @PersistenceContext(unitName = "TAG2PU")
    private EntityManager em;

    @Override
    protected EntityManager getEntityManager() {
        return em;
    }

    public SynchControllerFacade() {
        super(SynchController.class);
    }

    public SynchController findSynchControllerPerSerialNumber(Long serialNumber) {
        CriteriaBuilder cb = getEntityManager().getCriteriaBuilder();
        CriteriaQuery<SynchController> cq = cb.createQuery(SynchController.class);
        Root<SynchController> root = cq.from(SynchController.class);
        cq.where(cb.equal(root.get(SynchController_.serialNumber), serialNumber));
        SynchController synchController = null;
        try {
            synchController = getEntityManager().createQuery(cq).getSingleResult();
        } catch (NoResultException e) {
            e.printStackTrace();
            return null;
        }
        return synchController;
    }
}
